#!/usr/bin/env python3

import json, sys
import requests
import pprint

if len(sys.argv) < 2:
    print('Usage: weather.py location')
    sys.exit()

location = ' '.join(sys.argv[1:])

url = 'https://v0.yiketianqi.com/api?version=v61&appid=24578493&appsecret=LG27boer&city=' + location

response = requests.get(url)


weatherData = json.loads(response.text)

if 'errcode' in weatherData and weatherData['errcode'] == 100:
    print('未查询到'+location+'的实时天气数据')
    sys.exit()

pprint.pprint('现在'+location+'的温度是：'+ weatherData['tem'])
pprint.pprint('最高温度是：'+weatherData['tem1']+', 最低温度是:'+weatherData['tem2'])
pprint.pprint('今天在' + location + weatherData['air_tips']+', 空气质量：'+weatherData['aqi']['air_level'] )

